import 'package:flutter/material.dart';
import 'package:flutter_boost/boost_navigator.dart';
import 'package:flutter_boost/flutter_boost_app.dart';
import 'package:flutter_module/test/boost/pageOne.dart';
import 'package:flutter_module/test/boost/pageTwo.dart';
import 'package:flutter_module/test/test_page.dart';

import '../test_entry.dart';
import 'boot_intercept.dart';

class BoostApp extends StatefulWidget {
  @override
  _BoostAppState createState() => _BoostAppState();
}

class _BoostAppState extends State<BoostApp> {
  @override
  Widget build(BuildContext context) {
    Route<dynamic>? routeFactory(RouteSettings settings, String? uniqueId) {
      print("=========================");
      print(settings.arguments);
      print("=========================");
      FlutterBoostRouteFactory? factory;
      if (settings.name == "page_one") {
        factory = (setting, uniqueId) {
          return PageRouteBuilder<dynamic>(
              settings: settings,
              pageBuilder: (_, __, ___) {
                return PageOne();
              });
        };
      } else if (settings.name == "page_two") {
        factory = (setting, uniqueId) {
          return PageRouteBuilder<dynamic>(
              settings: settings,
              pageBuilder: (_, __, ___) {
                return PageTwo(setting.arguments);
              });
        };
      }else if (settings.name == "test_page") {
        factory = (setting, uniqueId) {
          return PageRouteBuilder<dynamic>(
              settings: settings,
              pageBuilder: (_, __, ___) {
                return TestPage();
              });
        };
      }else if (settings.name == "test_entry") {
        factory = (setting, uniqueId) {
          return PageRouteBuilder<dynamic>(
              settings: settings,
              pageBuilder: (_, __, ___) {
                return TestEntry();
              });
        };
      }
      if (factory == null) {
        return null;
      }
      return factory(settings, uniqueId);
    }

    return FlutterBoostApp(
      routeFactory,
      initialRoute: 'test_entry',
      interceptors: [CustomInterceptor()],//拦截器 在flutter界面间跳转有效
      // ,
      // appBuilder: appBuilder,// 加上appBuilder后 路由配置不生效，且界面无法返回？
    );
  }
}
